<template>
  <div class="author-recommend-arcs" v-if="articleList.length">
    <div class="title"><p class="linear-border-bottom">作者推荐</p></div>
    <ul class="article-list">
      <li @click="handleNavigator(item.id)" v-for="item in articleList" :key="item.id">
        <p class="arc-title">{{ item.articleTitle }}</p>
        <div class="arc-info">
          <span>{{ item.viewCounts | splitNumber }}阅读</span> · <span>{{ item.likeCounts }}点赞</span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'AuthorRecommend',
  props: {
    userId: String,
    articleId: String
  },
  data () {
    return {
      articleList: []
    }
  },
  created () {
    this.getAuthorRecommendArticles()
  },

  methods: {
    async getAuthorRecommendArticles () {
      const searchParams = {
        articleId: this.articleId,
        userId: this.userId
      }
      const data = await this.$axios.post('/gimishare/api/v1/articles/author-recommend', searchParams)
      this.articleList = data.data || []
    },

    handleNavigator (id) {
      const { href } = this.$router.resolve(`/post/${id}`)
      window.open(href, '_blank')
    }
  }
}
</script>
<style lang="less" scoped>
.author-recommend-arcs {
  background-color: #fff;
  margin-top: 12px;
  border-radius: 4px;
  padding: 10px 4px 10px 0;
  .title {
    padding: 0 20px;
    line-height: 36px;
    color: #000;
  }
  .article-list {
    list-style: none;
    margin: 0;
    margin-top: 10px;
    padding: 0;
    li {
      padding: 6px 20px;
      position: relative;
      cursor: pointer;
      &:hover {
        .arc-title {
          color: var(--primary-color);
        }
      }
      .arc-title {
        color: #333;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .arc-info {
        color: #999;
        font-size: 12px;
        margin-top: 4px;
      }
    }
  }
}
</style>
